home *** CD-ROM | disk | FTP | other *** search
- #ifndef MODULE_H
- #define MODULE_H
-
- /* This flag controls application code used to help debug plugin modules,
- * as well as debugging code within a module itself.
- */
- #ifndef ModuleDebug
- #define ModuleDebug 1
- #endif
-
-
- #ifndef MODULE_R_H
- #include "Module.r.h"
- #endif
-
- #ifndef CKIDEFS_H
- #include "ModuleSupport.h"
- #endif
-
-
- /* This is the common include file for both Plug-in modules and an application
- * which makes use of them. It defines the data structures which are visible
- * to a module. This file contains only application-independent data
- * structures; data structures specific to a particular application must be
- * defined elsewhere.
- */
-
-
- /* When a module is first loaded, we assign it a ModuleID which is then used
- * to refer to that module as long as it remains loaded. This is simply an
- * index into a table of loaded modules. Legal values are always positive;
- * zero or negative ModuleIDs indicate nil or error conditions. When a
- * module is unloaded, its ModuleID can be reused.
- *
- * Note that this is _not_ the module's permanent unique ID (the 32-bit value
- * stored in the module's 'MDdf' resource). It is a 16-bit tag used to refer
- * to a loaded module during a particular session of Arrange.
- */
- typedef Short ModuleID;
-
-
- struct ModuleParamBlock;
- typedef struct ModuleParamBlock ModuleParamBlock;
-
-
- /* The following declarations are required to allow modules to be compiled
- * using Think C, which has different parameter-passing conventions than
- * MPW C: namely, parameters are pushed in the opposite order (left-to-right
- * instead of right-to-left), 2-byte parameters are not expanded to 4 bytes,
- * and the callee is responsible for removing the parameters from the stack.
- *
- * By appending ", ..." to the end of each parameter list, we force Think C
- * to use the MPW-style calling conventions (except for the expansion of
- * 2-byte values to 4 bytes). This is done using the ENDP macro, which
- * expands to the empty string except when compiling under Think C. To
- * force 2-byte values to be expanded to 4 bytes, we define aliases for
- * ModuleID, Boolean, and Short to be used in parameter declarations.
- */
- #ifdef __SC__
- #define ENDP , ...
- typedef long pModuleID;
- typedef long pBoolean;
- typedef long pShort;
- #elif defined (__MWERKS__)
- #define ENDP
- typedef long pModuleID;
- typedef long pBoolean;
- typedef long pShort;
- #else // ndef __SC__
- #define ENDP
- typedef ModuleID pModuleID;
- typedef Boolean pBoolean;
- typedef Short pShort;
- #endif // else ndef __SC__
-
-
- /* Struct defining the QuickDraw global variables - used as a field in
- * ModuleSysInfo (below).
- */
- #if !UniversalIncludes
- struct QDGlobals
- {
- char privates[76];
- long randSeed;
- BitMap screenBits;
- Cursor arrow;
- Pattern dkGray;
- Pattern ltGray;
- Pattern gray;
- Pattern black;
- Pattern white;
- GrafPtr thePort;
- }; // QDGlobals
- #endif // if !UniversalIncludes
-
-
- // This struct contains info about a currently loaded Plugin module.
- struct ModuleInfo
- {
- Short vers; // Version number for this record (currently 1).
- FSSpec file; // File containing the module.
- Short fileRef; // Refnum for file's resource fork.
- Short defID; // ID of the module definition resource.
- ModuleID modID; // ModuleID assigned when this module was loaded.
- const void* appInfo; // Application-specific info (nil if unused).
-
- // Information copied from the ModuleDef record.
- uShort flags; // ModuleFlags values (set unused bits to zero).
- char name[32]; // Unique name (0-terminated) for this module.
- uInteger id; // Unique ID (registered with CKI) for this module.
- uInteger modVers; // Module version.
- Short rootCodeID; // ID of the root code resource ('MDcd') for this module
- // (code resource containing the module's boot function);
- // value is relative to the ID of the 'MDdf' resource.
- // -1 if module has no boot function.
- }; // ModuleInfo
-
-
- // This struct specifies an entry point within a loaded module.
- struct ModuleEntryPoint
- {
- ModuleID module; // ID of the module owning this entry point; 0 indicates
- // a "nil" value.
- Short rsrcID; // ID of the resource ('MDcd') containing the entry point.
- uInteger offset; // Entry point offset within the code resource.
-
- Boolean IsNil() { return module == 0; }
- Boolean NotNil() { return module != 0; }
-
- Boolean operator==(const ModuleEntryPoint &entry) const;
- Boolean operator!=(const ModuleEntryPoint &entry) const { return !operator==(entry); }
- }; // ModuleEntryPoint
-
-
- // This struct provides information about the machine on which we are running.
- struct ModuleSysInfo
- {
- Short vers; // Version number for this record (currently 2).
- Short pad; // Unused (always 0).
- Integer sysVers; // System software version number.
- Boolean hasFPU; // True if a floating-point coprocessor is present.
- Boolean hasColorQD; // True if Color QuickDraw is available.
- Rect screenBounds;// Bounds of the monitor containing the menu bar.
- FSSpec sysFolder; // Location of the system folder.
- FSSpec prefsFolder; // Location of the application's preferences folder,
- // or the system folder if the app doesn't create
- // a custom prefs folder.
-
- // Fields added in version 2 of ModuleSysInfo record:
-
- QDGlobals *qd; // pointer to QuickDraw globals
- }; // ModuleSysInfo
-
-
- /* This enum describes a particular build of the application in which a module
- * is running. It is used for the "flags" field of a ModuleAppInfo record.
- */
- enum MAppFlags
- {
- afInternalDebug = 1, // Application was compiled with internal debugging
- // code enabled.
- afModuleDebug = 2, // Application was compiled with module-debugging
- // code enabled.
- afDemoVersion = 4 // This is a demo version of the application (freely
- // distributable, some features disabled).
- }; // MAppFlags
-
-
- /* This struct provides information about the application inside which a
- * module has been loaded.
- */
- struct ModuleAppInfo
- {
- Short vers; // Version number for this record (currently 1).
- Short pad; // Unused (always 0).
- uInteger appID; // Unique identifier for this application.
- uInteger appVers; // Application version number.
- FSSpec appFile; // Location of the application file.
- Short appRefnum; // Refnum for the application's resource fork.
- MAppFlags flags; // Flags
- }; // ModuleAppInfo
-
-
- /* This struct lists the callback functions available for manipulating
- * modules themselves.
- */
- struct ModMgrCalls
- {
- Short vers; // Version number for this record (currently 1).
- Short pad; // Unused (always 0).
-
- ModuleID (*FindModuleName) (const char* name, uInteger minVers ENDP);
- ModuleID (*FindModuleID) (uInteger id, uInteger minVers ENDP);
- const ModuleInfo* (*GetModInfo) (pModuleID module ENDP);
- OSErr (*OpenModFile) (const FSSpec *file, pShort fileRefnum ENDP);
-
- ModuleEntryPoint (*GetModuleEntry) (pModuleID module, uInteger entryID ENDP);
- ProcPtr (*ModuleCallPrelude) ( const ModuleEntryPoint *entry,
- OUT ModuleParamBlock *pb ENDP );
- void (*ModuleCallEpilogue)( const ModuleEntryPoint *entry,
- const ModuleParamBlock *pb ENDP );
- }; // ModMgrCalls
-
-
- // This enum defines some parameters for functions in the MemCalls table.
- enum AllocMode { amFreeStore, // Allocate on the C++ free store.
- amPtr, // Allocate a Memory Manager pointer.
- amHdl, // Allocate a Memory Manager handle.
- amTypeMask = 0xFF, // Mask for previous options.
- amFriendly = 0x100, // Modifier to disallow allocations
- // which would put us near to running
- // out of memory.
- amClear = 0x200, // Modifier to initialize storage to 0s.
- amErrIfNoMem = 0x400 }; // Modifier to signal a fatal error,
- // rather than returning nil, if
- // allocation fails.
-
- #if defined (__SC__) || defined (__MWERKS__)
- typedef long pAllocMode;
- #else // ndef __SC__
- typedef AllocMode pAllocMode;
- #endif // else ndef __SC__
-
-
- /* This struct lists the callback functions available for memory allocation
- * and management.
- */
- struct MemCalls
- {
- Short vers; // Version number for this record (currently 1).
- Short pad; // Unused (always 0).
-
- void* (*AllocMem) (uInteger size, pAllocMode mode ENDP);
- void (*DeallocMem) (void* block, pAllocMode mode ENDP);
- uInteger (*MemAvailable) ();
- }; // MemCalls
-
-
- // This struct lists various utility callback functions.
- struct UtilCalls
- {
- Short vers; // Version number for this record (currently 1).
- Short pad; // Unused (always 0).
-
- const char* (*GetRString) (pShort rsrcID, pShort stringIndex ENDP);
- void (*LowerString) (IO char* string, Integer length ENDP);
- }; // UtilCalls
-
-
- /* This struct lists the callback functions available for reporting error
- * conditions.
- */
- struct ErrorCalls
- {
- Short vers; // Version number for this record (currently 1).
- Short pad; // Unused (always 0).
- }; // ErrorCalls
-
-
- /* This struct lists the callback functions available for debugging purposes.
- * These functions are only available if the application has been compiled for
- * module debugging.
- */
- struct DebugCalls
- {
- Short vers; // Version number for this record (currently 1).
- Short pad; // Unused (always 0).
-
- void (*PrintToLog) (const char* message ENDP);
- }; // DebugCalls
-
-
- /* This struct contains a set of function pointers into the application code
- * which can be called from a plugin module.
- */
- struct CallbackTbl
- {
- Short vers; // Version number for this record (currently 1).
- Short pad; // Unused (always 0).
- ModMgrCalls* modMgr; // Module Manager functions.
- MemCalls* mem; // Memory allocation/deallocation functions.
- UtilCalls* util; // Utility functions
- ErrorCalls* err; // Error-logging functions.
- DebugCalls* dbg; // Debugging functions; nil in non-debug builds.
- const void* extra1; // Unused (always nil).
- const void* extra2; // Unused (always nil).
- const void* extra3; // Unused (always nil).
- }; // CallbackTbl
-
-
- /* This struct defines the parameter block which is passed as the first
- * parameter to all module entry points. An entry point may have additional
- * parameters, depending on the specific function being called.
- */
- struct ModuleParamBlock
- {
- Short vers; // Version number for this record (currently 1).
- Short pad; // Unused (currently 0).
- uInteger moduleRefcon; // Module refcon value.
- uInteger hookRefcon; // Hook-specific refcon value.
- const ModuleSysInfo* sys; // Pointer to information about this machine.
- const ModuleAppInfo* app; // Pointer to information about the application.
- const ModuleInfo* mod; // Pointer to information about this module.
- const CallbackTbl* calls; // Pointer to table of callback functions.
- const void* extra1; // Unused (always nil).
- const void* extra2; // Unused (always nil);
- const void* extra3; // Unused (always nil);
- }; // ModuleParamBlock
-
-
- // Values for the action parameter of a module's root entry routine.
- enum ModuleRootAction
- {
- mrLoad, // Module is being loaded - return 1 if module initializes
- // successfully, 0 otherwise.
- mrUnload, // Module is being unloaded. Function result is ignored.
- mrFindEntry // Request for address of a specific entry point in the
- // module. Return a ProcPtr, or nil if entry point isn't
- // available.
- };
-
- #ifdef __SC__
- typedef long pModuleRootAction;
- #elif defined (__MWERKS__)
- typedef long pModuleRootAction;
- #else
- typedef ModuleRootAction pModuleRootAction;
- #endif
-
- /* Prototype for a module's root entry point (the function at the beginning
- * of the root code resource).
- */
- Integer ModuleRoot(ModuleParamBlock *pb, pModuleRootAction action, Integer p1 ENDP);
-
- typedef Integer (*ModuleRootProc)(ModuleParamBlock*, pModuleRootAction, Integer ENDP);
-
- #endif // #ifndef MODULE_H